﻿#include "WorkThread.h"

#include <chrono>
#include <iostream>
#include <sstream>
#include <iomanip>

#include <QDebug>

WorkThread::WorkThread()
    : m_start_thread(true)
{
    // 创建线程
    std::thread t(&WorkThread::run, this);

    // 与猪线程隔离开，不阻塞主线程运行
    t.detach();

    //qDebug() << "Thread ID:" << getHexThreadId(&t);
}

void WorkThread::run(void *param)
{
    WorkThread* w = (WorkThread*)param;
    while(true)
    {
        if(w && w->m_start_thread)
        {
            // 执行具体的工作
            //qDebug() << "test...";
            std::this_thread::sleep_for(std::chrono::milliseconds(10));
        }
        else
        {
            // 睡眠10ms
            std::this_thread::sleep_for(std::chrono::milliseconds(10));
        }
    }
}
